import wx
import random

class MyFrame(wx.Frame):
    nameList = ['tom', 'jerry', 'fendi', 'wendy']
    def __init__(self):
        super().__init__(None, title='Lottery Machine', size=(600, 600), pos=(100, 100))
        # 面板
        self.pl = wx.Panel(self, size=(400, 400), pos=(100, 100))
        # 设置背景颜色
        # self.SetBackgroundColour(wx.BLUE)
        # self.SetBackgroundColour('#FF0000')
        self.SetBackgroundColour((255, 255, 0))

        # 静态文本
        self.staticText = wx.StaticText(self.pl, label='Welcome to use lottery machine', pos=(200, 100), style=wx.TE_CENTER)
        self.lotteryText = wx.StaticText(self.pl, pos=(250, 200), style=wx.TE_CENTER)
        # 创建字体，字体大小、字体包、字体风格、加粗
        font = wx.Font(24, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD)
        # 静态文本设置成我们自己创建的字体
        self.lotteryText.SetFont(font)

        # 按钮
        self.startBtn = wx.Button(self.pl, label='Start the lottery', pos=(100, 500))
        self.Bind(wx.EVT_BUTTON, self.onStart, self.startBtn)
        self.stopBtn = wx.Button(self.pl, label='Stop the lottery', pos=(400, 500))
        self.Bind(wx.EVT_BUTTON, self.onStop, self.stopBtn)


    # 抽奖
    def onStart(self, event):
        # 创建定时器
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update_name, self.timer)
        # 每隔100毫秒更新名字
        self.timer.Start(100)


    def update_name(self, event):
        self.lotteryText.SetLabelText(random.choice(MyFrame.nameList))

    def onStop(self, event):
        # 停止计时器
        self.timer.Stop()

# Python程序主入口
if __name__ == '__main__':
    app = wx.App()
    frm = MyFrame()
    frm.Show()
    app.MainLoop()